﻿using Kavaa.Core.Data;
using Kavaa.Modules.PortailMedical.Entity;
using System;
using System.Data.SqlClient;
using Kavaa.Core.Tracing;
using System.Collections;
using System.Collections.Generic;

namespace Kavaa.Modules.PortailMedical.Datalayer
{
    internal static class ActeDAO
    {
        public static Actes GetActes()
        {
            Actes actes = new Actes();

            foreach (var row in SqlDaoAdapter.ExecuteReader(
                ConfigurationCache.DatabaseConnectionString,
                "[dbo].[sp_PortailMedical_GetActes]"
           ))
            {
                actes.Add(new Acte()
                {
                    Id = (row["ActeId"] != DBNull.Value) ? Convert.ToInt32(row["ActeId"]) : 0,
                    Name = (row["ActeName"] != DBNull.Value) ? Convert.ToString(row["ActeName"]) : null,
                    Valeur = (row["ActeValeur"] != DBNull.Value) ? Convert.ToInt32(row["ActeValeur"]) : 0,
                    Nomenclature = new Nomenclature() { Id = (row["ActeNomenclature"] != DBNull.Value) ? Convert.ToInt32(row["ActeNomenclature"]) : 0 },

                });
            }

            return actes;
            //Actes actes = new Actes();
            //Acte acte = new Acte() { Id = 1, Intitule = "Acte 1" };
            //actes.Add(acte);
            //return new Actes() { { new Acte() { Id = 1, Intitule = "Acte 1" } } };

        }

        public static Actes GetActesByClinique(int idclinique)
        {
            Actes actes = new Actes();

            foreach (var row in SqlDaoAdapter.ExecuteReader(
                ConfigurationCache.DatabaseConnectionString,
                "[dbo].[sp_PortailMedical_GetActesByClinique]", new List<SqlParameter>() { 
                new SqlParameter("@CliniqueId", idclinique),
       
            }
           ))
            {
                actes.Add(new Acte()
                {
                    Id = (row["ActeId"] != DBNull.Value) ? Convert.ToInt32(row["ActeId"]) : 0,
                    Name = (row["ActeName"] != DBNull.Value) ? Convert.ToString(row["ActeName"]) : null,
                });
            }

            return actes;

        }

        public static Actes GetActesCategorie(int idcategorie)
        {
            Actes actes = new Actes();

            foreach (var row in SqlDaoAdapter.ExecuteReader(
                ConfigurationCache.DatabaseConnectionString,
                "[dbo].[sp_PortailMedical_GetActesCategorie]", new List<SqlParameter>() { 
                new SqlParameter("@IdCategorie", idcategorie),
       
            }
           ))
            {
                actes.Add(new Acte()
                {
                    Id = (row["ActeId"] != DBNull.Value) ? Convert.ToInt32(row["ActeId"]) : 0,
                    Name = (row["ActeName"] != DBNull.Value) ? Convert.ToString(row["ActeName"]) : null,
                });
            }

            return actes;

        }
        public static void SaveActeClinique(int ActeId, int CliniqueId)
        {
            SqlDaoAdapter.ExecuteNonQuery(ConfigurationCache.DatabaseConnectionString,
                "[dbo].[sp_PortailMedical_SaveActeClinique]"
            , new List<SqlParameter>() { 
                new SqlParameter("@ActeId", ActeId),
                new SqlParameter("@CliniqueId", CliniqueId)
              
               
            });
        }

    }
}
